package com.njupt.swg.threadstudyjimin.item05.singleton;

import com.njupt.swg.threadstudyjimin.annotation.Recommend;
import com.njupt.swg.threadstudyjimin.annotation.ThreadSafe;

@ThreadSafe
@Recommend
public class SingletonExample5 {
    private SingletonExample5(){}

    public static SingletonExample5 getInstance(){
        return Singleton.INSTANCE.getInstance();
    }

    private enum Singleton{
        INSTANCE;

        private SingletonExample5 singleton;

        //JVM保证这个方法绝对只调用一次
        Singleton(){
            singleton = new SingletonExample5();
        }

        public SingletonExample5 getInstance(){
            return singleton;
        }
    }
}
